package com.eeds.service.culture.impl;

import com.eeds.common.model.PageInfo;
import com.eeds.common.table.CultureEntity;
import com.eeds.dao.CultureDao;
import com.eeds.date.DateUtil;
import com.eeds.model.culture.req.ReqAddCultureVO;
import com.eeds.model.culture.req.ReqGetCultureInfoVO;
import com.eeds.model.culture.req.ReqUpdateCultureVO;
import com.eeds.model.culture.res.ResGetCultureListVO;
import com.eeds.model.culture.vo.CultureVO;
import com.eeds.service.culture.CultureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CultureServiceImpl implements CultureService {

    @Autowired
    private CultureDao cultureDao;

    /**
     * 添加文化
     *
     * @param reqAddCultureVO
     * @return
     */
    @Override
    public Integer addCulture(ReqAddCultureVO reqAddCultureVO) {
        CultureEntity cultureEntity  = new CultureEntity();
        cultureEntity.setContent(reqAddCultureVO.getContent());
        cultureEntity.setTitle(reqAddCultureVO.getTitle());
        cultureEntity.setType(reqAddCultureVO.getType());
        Date date = DateUtil.nowDate();
        cultureEntity.setCreateTime(date);
        cultureEntity.setUpdateTime(date);
        cultureDao.insert(cultureEntity);
        return 1;
    }

    /**
     * 修改文化
     *
     * @param reqUpdateCultureVO
     * @return
     */
    @Override
    public Integer updateCulture(ReqUpdateCultureVO reqUpdateCultureVO) {
        CultureEntity cultureEntity  = new CultureEntity();
        cultureEntity.setContent(reqUpdateCultureVO.getContent());
        cultureEntity.setTitle(reqUpdateCultureVO.getTitle());
        Date date = DateUtil.nowDate();
        cultureEntity.setUpdateTime(date);
        cultureEntity.setIdCulture(reqUpdateCultureVO.getIdCulture());
        cultureDao.updateById(cultureEntity);
        return 1;
    }

    /**
     * 获取文化列表
     *
     * @return
     */
    @Override
    public PageInfo<ResGetCultureListVO> getCultureList() {
        PageInfo<ResGetCultureListVO> pageInfo = new PageInfo<>();
        List<ResGetCultureListVO> list = cultureDao.getCultureList();
        pageInfo.setData(list);
        pageInfo.setTotalResult(list.size());
        return pageInfo;
    }

    /**
     * 获取文化信息
     *
     * @param reqGetCultureInfoVO
     * @return
     */
    @Override
    public CultureVO getCultureInfo(ReqGetCultureInfoVO reqGetCultureInfoVO) {
        return cultureDao.getCultureInfo(reqGetCultureInfoVO);
    }
}
